#ifndef BMS_CAN_H
#define BMS_CAN_H

#define BMS_CAN_LOST_TIME	(2000/10)
typedef struct
{
	UINT16 u16LostCnt;
	UINT8 fRxUpdate:1;
	UINT8 fRxLost:1;
}structBmsCanRxCtrl;
typedef struct
{
	union
	{
		UINT8 Bytes[8];
		struct
		{
			UINT8 u16VBusHi;
			UINT8 u16VBusLo;
			UINT8 u16CurHi;
			UINT8 u16CurLo;
			UINT8 u16SOCHi;
			UINT8 u16SOCLo;

			UINT8 fChargeUnitOverVol:1;
			UINT8 fChargeTotalOverVol:1;
			UINT8 fChargeOverTemp:1;
			UINT8 fChargeUnderTemp:1;
			UINT8 fChargeOverCur:1;
			UINT8 fChargeMachineErr:1;
			UINT8 fInsulationTooLow:1;
			UINT8 fBmsCommBreak:1;

			UINT8 fDisChargeUnitOverVol:1;
			UINT8 fDisChargeTotalOverVol:1;
			UINT8 fDisChargeOverTemp:1;
			UINT8 fDisChargeUnderTemp:1;
			UINT8 fDisChargeOverCur:1;
			UINT8 fVolDiffOver:1;
			UINT8 fTempDiffOver:1;
			UINT8 fDangerousVoltageProtection:1;
		}bit;
	}unRx0x1801FFF4;
	union
	{
		UINT8 Bytes[8];
		struct
		{
			UINT8 u16SingleVolMaxHi;
			UINT8 u16SingleVolMaxLo;
			UINT8 u8NumOfSingleVolMax;
			UINT8 u16SingleVolMinHi;
			UINT8 u16SingleVolMinLo;
			UINT8 u8NumOfSingleVolMin;
			
			UINT8 fSamplingLineFallOff:1;
			UINT8 fTempSensorFallOff:1;
			UINT8 fDisChargeRelayAdhesion:1;
			UINT8 fFastChargeRelayAdhesion:1;
			UINT8 fHeatChargeRelayAdhesion:1;
			UINT8 fHeatFilmTempHigh:1;
			UINT8 fFastChargeSocketErr:1;
			UINT8 fSingleVolTooLow:1;

			UINT8 u8Byte7NC;
		}bit;
	}unRx0x1802FFF4;
	union
	{
		UINT8 Bytes[8];
		struct
		{
			UINT8 u16SingleTempMax;
			UINT8 u8NumOfSingleTempMax;
			UINT8 u16SingleTempMin;
			UINT8 u8NumOfSingleTempMin;
			
			UINT8 u16PIR_Hi;
			UINT8 u16PIR_Lo;
			UINT8 u16NIR_Hi;
			UINT8 u16NIR_Lo;
		}bit;
	}unRx0x1803FFF4;
	union
	{
		UINT8 Bytes[8];
		struct
		{
			UINT8 fDisChargeRelayState:1;
			UINT8 fFastChargeRelayState:1;
			UINT8 fPreChargeRelayState:1;
			UINT8 fHeatRelayState:1;
			UINT8 Byte0NC:4;
			
			UINT8 u16VolACC_Hi;
			UINT8 u16VolACC_Lo;
			UINT8 u16VolKeyOn_Hi;
			UINT8 u16VolKeyOn_Lo;
			UINT8 u16VolCHG_Hi;
			UINT8 u16VolCHG_Lo;
			
			UINT8 Byte7NC;
		}bit;
	}unRx0x1804FFF4;
	union
	{
		UINT8 Bytes[8];
		struct
		{
			UINT8 u8BatteryState;
			UINT8 u8BatteryThermalManageMode;
			UINT8 u8FaultHighestLevel;
			
			UINT8 u16ChargeTimesHi;
			UINT8 u16ChargeTimesLo;

			UINT8 U16SettedChargeCurRefHi;
			UINT8 U16SettedChargeCurRefLo;
		}bit;
	}unRx0x1805FFF4;
	union
	{
		UINT8 Bytes[8];
		struct
		{
			UINT8 u16SOH_Hi;
			UINT8 u16SOH_Lo;
			UINT8 BytesNc[6];
		}bit;
	}unRx0x1806FFF4;
	union
	{
		structBmsCanRxCtrl stBmsCanRxCtrlArr[6];
		struct
		{
			structBmsCanRxCtrl stBmsCanRxCtrl0x1801FFF4;
			structBmsCanRxCtrl stBmsCanRxCtrl0x1802FFF4;
			structBmsCanRxCtrl stBmsCanRxCtrl0x1803FFF4;
			structBmsCanRxCtrl stBmsCanRxCtrl0x1804FFF4;
			structBmsCanRxCtrl stBmsCanRxCtrl0x1805FFF4;
			structBmsCanRxCtrl stBmsCanRxCtrl0x1806FFF4;
		}bit;
	}unRxCtrl;
	//
	union
	{
		UINT8 Bytes[8];
		struct
		{
			UINT8 U16SetChargeCurRefHi;
			UINT8 U16SetChargeCurRefLo;
			UINT8 BytesNc[6];
		}bit;
	}unTx0x1800F4FF;//100ms
	union
	{
		UINT8 Bytes[8];
		struct
		{
			UINT8 U16SetExtendedRangeChargeCurRefHi;
			UINT8 U16SetExtendedRangeChargeCurRefLo;
			UINT8 BytesNc[6];
		}bit;
	}unTx0x1801F4FF;//100ms
	union
	{
		UINT8 Bytes[8];
		struct
		{
			UINT8 BytesNc1[4];
			UINT8 u8RangeExtenderStatus:3;
			UINT8 Byte5NC:5;
			UINT8 BytesNc2[3];
		}bit;
	}unTx0x18FD8C27;//100ms
}structBmsCan;
extern structBmsCan stBmsCan;
extern void vProcBmsCanRx(void);//10ms
extern void vProcBmsCanTx(void);//10ms
extern void vBMSCanFastRxCallBack(UINT16 u16_id_hi,UINT16 u16_id_lo,UINT8 u8_length,UINT8 *pData);

#endif
